
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2019/4/29 17:57
# @Author  : 何胜金-heshengjin
# @Site    : 
# @File    : closure_test.py
# @Software: PyCharm
"""
 python 的变量作用域看起来和JavaScript一致

 nonlocal《只会在闭包函数查找》

 global设为全局变量,使用全局的
"""

def test_nonLocal(time):
    def test_inner_nonLocal(min):
        #time不是本函数定义的，外部命名空间的
        #只会在闭包函数查找
        nonlocal  time
        time = time + min
        return time
    return test_inner_nonLocal

def test_global():
    global x
    print(x)
    x = 100

if __name__ == '__main__':

    f = test_nonLocal(0)
    print(f(2))
    print(f(10))

    print('''*****************************************''')

    x = 123
    test_global()
    print(x)